package projectx.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

public class CollectionUtil {

	// --------------------------------------------------------------------------
	// C O N S T R U C T O R S
	//
	// --------------------------------------------------------------------------
	private CollectionUtil() {
		super();
	}

	// --------------------------------------------------------------------------
	// S T A T I C M E T H O D S
	//
	// --------------------------------------------------------------------------

	public static boolean isEmpty(String[] array) {
		if (array == null || array.length == 0) {
			return true;
		}

		for (int i = 0; i < array.length; i++) {
			if (!StringUtil.isBlank(array[i])) {
				return false;
			}
		}

		return true;
	}

	public static boolean isEmpty(Collection collection) {
		// return collection == null && collection.isEmpty();
		return collection == null || collection.isEmpty();
	}

	public static int getSize(Collection collection) {

		if (collection == null) {
			return 0;
		}
		return collection.size();
	}

	public static int getSize(Map map) {

		if (map == null) {
			return 0;
		}
		return map.size();
	}

	public static ArrayList loadFromIterator(Iterator it) {
		ArrayList list = new ArrayList();
		if (it != null) {
			while (it.hasNext()) {
				list.add(it.next());
			}
		}
		return list;
	}
}
